Skip to main content

AMQP

The Mobilidata Interchange is an AMQP broker. More info about the technology can be found on amqp.org. AMQP is a binary protocol, so you need a client library to connect to the broker. The following examples are using the amqpnetlite library.

Basic code snippets are given here as reference.

caution

These code snippets are intend to be used as reference only. They are not production ready.

Connection configuration

C# example with amqpnetlite
string brokerAddress = $"amqps://{host}:{port}";

ConnectionFactory factory = new ConnectionFactory();
factory.SASL.Profile = SaslProfile.External;
factory.SSL.ClientCertificates.Add(X509Certificate2.CreateFromPemFile("<yourCertificate>.crt", "<yourPrivateRSAKey>.pem"));
factory.SSL.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
{
return X509Certificate2.CreateFromPemFile("<yourCertificate>.crt", "<yourPrivateRSAKey>.pem");
};

The certificate and private key files are the same as used by the Local Actor API connection. See Local Actor API for more information on using the certificate to request the subscription.

Connecting and receiving messages

C# example with amqpnetlite
Address address = new Address(brokerAddress);
connection = await factory.CreateAsync(address);
Session session = new Session(connection);

ReceiverLink receiver = new ReceiverLink(session, "receiver-link", source);
Message message = null;
TimeSpan timeout = TimeSpan.MaxValue;

while (true)
{
message = await receiver.ReceiveAsync(timeout);
if (message != null)
{
// Do something with the message
receiver.Accept(message);
}
}